package com.bw.a2207a.base

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import java.lang.reflect.ParameterizedType

/**
 *
 * @ClassName: BaseActivity
 * @Description: 通过反射获取ViewModel
 * @Author: zhangyanchao
 * @CreateDate: 2024/10/16 4:05 PM
 * @Version: 1.0
 */
abstract class BaseViewBindingActivity<DB : ViewDataBinding>(val layoutId: Int) :
    AppCompatActivity() {

    //延时初始化 lateinit
    lateinit var binding: DB

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        binding = DataBindingUtil.setContentView(this, layoutId)
        binding.lifecycleOwner = this


        initView()
        initData()
    }

    abstract fun initData()

    abstract fun initView()

    override fun onDestroy() {
        super.onDestroy()
        //防止内存泄漏
        binding.unbind()
    }

}